$(document).ready( function() {
	$("#ordering :checkbox").css({"display":"none"});
	$("#ordering div[id*='stock']").each( function() {
		var thisProductID = $(this).attr("id").replace("_stockStatus","");
		if ( $(this).text().indexOf("OUT") != -1 ) {
			$(this).text("SOLD OUT");
			$("#"+thisProductID+"_btnAddToCart").remove();
			$("#"+thisProductID+"_qnty").remove();
			$("#"+thisProductID+"_check").remove();
		} else {
			// empty out the existing options and add the actual number available.
			$("#"+thisProductID+"_qnty").empty();
			var regex = /[0-9]+/;
			var regexMatch = regex.exec($(this).text());
			regexMatch = ( regexMatch > 100 ) ? 100 : regexMatch;
			for ( i=0; i<=regexMatch; i++ ) {
				$("#"+thisProductID+"_qnty").append("<option value='"+i+"'>"+i+"</option>");
			}
		}
	});
	$("#ordering select[id*='qnty']").change( function() {
		var checkboxToToggle = $(this).attr("id").replace("_qnty","");
		if ( $(this).val() != 0 ) {	
			$("#"+checkboxToToggle+"_check").attr({checked:true});
		} else {
			$("#"+checkboxToToggle+"_check").attr({checked:false});
		}
	});
	$("#orderForm").submit( function() {
		var validate = false;
		$("#orderForm select").each( function() {
			if ( $(this).val() != 0 ) {
				validate = true;
			}
		});
		if ( validate == false ) {
			alert("You must select a quantity for an item");
			return false;
		}
	});
	$("#ordering tr:gt(0):even").addClass("row1");
	
	/************/
	/* LIGHTBOX */
	/************/
	$("a[class='lightbox']").lightBox();
	$("#extraViews a").mouseover( function() {
		var mediumImage = $(this).find("img").attr("src");
		mediumImage = mediumImage.replace("ss_size3","ss_size1");
		var newMiGraphic = new Image();
		newMiGraphic.src = mediumImage;
		var newMiGraphicWidth = newMiGraphic.width;
		var newMiGraphicHeight = newMiGraphic.height
		$("#moreInformationGraphic").attr({src:mediumImage,width:newMiGraphicWidth,height:newMiGraphicHeight});	});
});